<%--
  Created by IntelliJ IDEA.
  User: haojianlei
  Date: 2018-11-23
  Time: 13:45
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title> - 空白页</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="${pageContext.request.contextPath}/assets/shipui/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/assets/shipui/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/assets/shipui/css/animate.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/assets/shipui/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/assets/ship/ship.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/assets/shipui/css/plugins/sweetalert/sweetalert.css"
          rel="stylesheet">
    <link href="${pageContext.request.contextPath}/assets/layui/css/layui.css" rel="stylesheet">
    <style>
        .planTxt{
            cursor: pointer;
        }
        .planTxt:hover{
            color: #0d8ddb;
        }
        .planTxtStatus{
            color:white;
            margin-left:3px;
            font-size:13px;
            line-height: 0;
            border-radius: 10px;
            padding: 2px
        }
    </style>

</head>

<body class="gray-bg">
<div class="row wrapper border-bottom white-bg page-heading" style="padding: 0px 20px 10px">
    <div class="row" style="margin-top: 20px">
        <div class="col-sm-4" style="margin-left: 18px">
            <ol class="breadcrumb">
                <li>
                    <a href="toTransportHome.do">运输计划</a>
                </li>
                <li>
                    <strong>计划列表</strong>
                </li>
            </ol>
        </div>
        <div class="col-sm-8">
            <%--备用--%>
        </div>
    </div>

    <div class="row" style="margin-top: 30px;margin-left: 10px">
        <div class="form-group" style="font-size: 16px;margin-left: -7px">
            <div class="col-xs-1 col-sm-1">
                <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#addPlan"
                        onclick="showAddPlanData()">+ 新增计划
                </button>
            </div>
            <div class="col-xs-2 col-sm-2" style="margin-left: 50px">
                <input type="text" class="form-control" name="ordernumber" id="orderNumberSearch" placeholder="请输入计划编号"
                       value="">
            </div>
            <div class="col-xs-2 col-sm-2">
                <input type="text" class="form-control" name="ordernumber" id="huoZhuSearch" placeholder="请输入货主名称"
                       value="">
            </div>
            <div class="col-xs-3 col-sm-3">
                <input type="text" class="form-control" name="ordernumber" id="timeSearch" placeholder="请选择时间范围"
                       value="">
            </div>
            <div class="col-xs-2 col-sm-2">
                <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#addShip"
                       id="orderNumberSearchButton" onclick="searchPlan()">查找计划
                </button>
            </div>
            <div class="col-xs-1 col-sm-1">
                <span><a style="display: none" id = "downloadExcel"></a></span>
            </div>

        </div>

    </div>

    <div id="myTab" class="shipTab">
        <span class="shipTabText  shipTabText-click" style="font-size: 16px" state=5 id="allShipSpan">
            <a href="#allShip" data-toggle="tab">
                全部计划
            </a>
        </span>
        <span class="shipTabText" state=0><a href="#planWks" data-toggle="tab">未开始</a></span>
        <span class="shipTabText" state=1><a href="#planYsz" data-toggle="tab">运输中</a></span>
        <span class="shipTabText" state=2><a href="#planWc" data-toggle="tab">已完成</a></span>
        <span class="shipTabText" state=3><a href="#planYq" data-toggle="tab">已延期</a></span>
        <span class="shipTabText" state=4><a href="#planZz" data-toggle="tab">已中止</a></span>

    </div>

</div>

<div class="wrapper wrapper-content">
    <div class="row">

        <%--全部运输计划--%>
        <div id="myTabContent" class="tab-content">
            <div class="tab-pane fade in active" id="allShip">
            </div>

            <%--未开始--%>
            <div class="tab-pane fade" id="planWks">
            </div>
            <%--运输中--%>
            <div class="tab-pane fade" id="planYsz">
            </div>
            <%--已完成--%>
            <div class="tab-pane fade" id="planWc">
            </div>
            <%--已延期--%>
            <div class="tab-pane fade" id="planYq">
            </div>
            <%--已终止--%>
            <div class="tab-pane fade" id="planZz">
            </div>
        </div>

    </div>

</div>

<%--新增计划模态框--%>
<div class="modal fade" id="addPlan" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"
     style="overflow: auto" data-backdrop="static">
    <div class="modal-dialog" style="width:50%;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h3 class="modal-title">
                    新增计划
                </h3>
            </div>
            <div class="modal-body">

                <div class="form-horizontal m-t">

                <div class="form-group">
                    <div class="row">
                    <label class="col-sm-3 control-label">计划编号：</label>
                    <div class="col-sm-8">
                        <input id="tmsNumber" name="tmsNumber" class="form-control" type="text" placeholder="必填">
                    </div>
                    </div>
                </div>

                <div class="form-group">
                    <div class="row">
                        <label class="col-sm-3 control-label" style="margin-top: 3px">选择货种：</label>
                        <div class="col-sm-4" style="font-size: 14px;margin-top: 5px">
                            <select class="form-control" id="huoZhong">
                            </select>
                        </div>
                        <div class="col-sm-3">
                            <button class="btn btn-default" type="submit" style="margin-top: 3px"><a href="toGoodName.do">+添加货种</a> </button>
                        </div>
                    </div>
                </div>

                <div class="form-group">
                    <div class="row">
                        <label class="col-sm-3 control-label">装货港口：</label>
                        <div class="col-sm-4" style="font-size: 14px;">
                            <select class="form-control" id="originalPort">
                            </select>
                        </div>
                        <div class="col-sm-3">
                            <button class="btn btn-default" type="submit"><a href="toLogistics.do">+添加港口</a></button>
                        </div>
                    </div>
                </div>

                <div class="form-group">
                    <div class="row">
                        <label class="col-sm-3 control-label">卸货港口：</label>
                        <div class="col-sm-4" style="font-size: 14px;">
                            <select class="form-control" id="destinationPort">
                            </select>
                        </div>
                        <div class="col-sm-3">
                            <button class="btn btn-default" type="submit"><a href="toLogistics.do">+添加港口</a></button>
                        </div>
                    </div>
                </div>

                <div class="form-group">
                    <div class="row">
                        <label class="col-sm-3 control-label">计划吨位：</label>
                        <div class="col-sm-8">
                            <input id="planTon" name="text" class="form-control" type="text">
                        </div>
                    </div>

                </div>

                <div class="form-group">
                    <div class="row">
                        <label class="col-sm-3 control-label">选择货主：</label>
                        <div class="col-sm-4" style="font-size: 14px;margin-top: 5px">
                            <select class="form-control" id="huoZhu">
                            </select>
                        </div>
                        <div class="col-sm-3">
                            <button class="btn btn-default" type="submit" style="margin-top: 5px"><a href="toGooderName.do"> +添加货主</a></button>
                        </div>
                    </div>
                </div>

                <div class="form-group">
                    <div class="row">
                        <label class="col-sm-3 control-label">计划负责人：</label>
                    <div class="col-sm-8">
                        <input id="planEmploy" name="planEmploy" class="form-control" type="text">
                    </div>
                    </div>
                </div>

                <div class="form-group">
                    <div class="row">
                        <label class="col-sm-3 control-label">计划开始时间：</label>
                    <div class="col-sm-8">
                        <input id="startTime" name="startTime" class="form-control" type="text">
                    </div>
                    </div>
                </div>

                <div class="form-group">
                    <div class="row">
                         <label class="col-sm-3 control-label">计划结束时间：</label>
                    <div class="col-sm-8">
                        <input id="endTime" name="endTime" class="form-control" type="text">
                    </div>
                    </div>
                </div>

                <div class="form-group">
                    <div class="row">
                    <div class="col-sm-8 col-sm-offset-3">
                        <button class="btn btn-primary" onclick="addPlanModel()">立即新增</button>
                    </div>
                    </div>
                </div>
            </div>
            </div>
        </div>
    </div><!-- /.modal-content -->
</div><!-- /.modal -->


<%--编辑计划模态框--%>
<div class="modal fade" id="editPlan" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="overflow: auto" data-backdrop="static">
    <div class="modal-dialog" style="width:50%;">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h3 class="modal-title">
                    编辑计划
                </h3>
            </div>
            <div class="modal-body">
                <div class="form-horizontal m-t">
                <div class="form-group">
                    <label class="col-sm-3 control-label">计划编号：</label>
                    <div class="col-sm-8">
                        <input id="planIdEdit" style="display: none" type="text">
                        <input id="transportStateEdit" style="display: none" type="text">
                        <input id="transportStateNameEdit" style="display: none" type="text">
                        <input id="tmsNumberEdit" name="tmsNumber" class="form-control" type="text"
                               placeholder="必填">
                    </div>
                </div>
                <div class="form-group">
                    <div class="row">
                        <label class="col-sm-3 control-label" style="margin-left: 7px">选择货种：</label>
                        <div class="col-sm-4" style="font-size: 14px;margin-top: 5px">
                            <select class="form-control" id="editHuoZhong">
                            </select>
                        </div>
                        <div class="col-sm-3">
                            <button class="btn btn-default" type="submit" style="margin-top: 5px"><a href="toGoodName.do">+添加货种</a></button>
                        </div>
                    </div>

                </div>
                <div class="form-group">
                    <div class="row">
                        <label class="col-sm-3 control-label" style="margin-left: 7px">装货港口：</label>
                        <div class="col-sm-4" style="font-size: 14px;margin-top: 5px">
                            <select class="form-control" id="editOriginalPort">
                            </select>
                        </div>
                        <div class="col-sm-3">
                            <button class="btn btn-default" type="submit" style="margin-top: 5px"><a href="toLogistics.do">+添加港口</a></button>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="row">
                        <label class="col-sm-3 control-label" style="margin-left: 7px">卸货港口：</label>
                        <div class="col-sm-4" style="font-size: 14px;margin-top: 5px">
                            <select class="form-control" id="editDestinationPort">
                            </select>
                        </div>
                        <div class="col-sm-3">
                            <button class="btn btn-default" type="submit" style="margin-top: 5px"><a href="toLogistics.do">+添加港口</a></button>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">计划吨位：</label>
                    <div class="col-sm-8">
                        <input id="planTonEdit" name="password" class="form-control" type="text">
                    </div>
                </div>
                <div class="form-group">
                    <div class="row">
                        <label class="col-sm-3 control-label" style="margin-left: 7px">选择货主：</label>
                        <div class="col-sm-4" style="font-size: 14px;margin-top: 5px">
                            <select class="form-control" id="editHuoZhu">
                            </select>
                        </div>
                        <div class="col-sm-3">
                            <button class="btn btn-default" type="submit" style="margin-top: 5px"><a href="toGooderName.do">+添加货主</a></button>
                        </div>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-sm-3 control-label">计划负责人：</label>
                    <div class="col-sm-8">
                        <input id="planEmployEdit" name="planEmploy" class="form-control" type="text">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">计划开始时间：</label>
                    <div class="col-sm-8">
                        <input id="startTimeEdit" name="startTime" class="form-control" type="text">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-3 control-label">计划结束时间：</label>
                    <div class="col-sm-8">
                        <input id="endTimeEdit" name="endTime" class="form-control" type="text">
                    </div>
                </div>

                <div class="form-group">
                    <div class="col-sm-8 col-sm-offset-3">
                        <button class="btn btn-primary" type="submit" onclick="editPlanModel()">编辑完成</button>
                    </div>
                </div>
            </div>
            </div>
        </div>
    </div><!-- /.modal-content -->
</div><!-- /.modal -->

<!-- 全局js -->
<script src="${pageContext.request.contextPath}/assets/shipui/js/jquery.min.js?v=2.1.4"></script>
<script src="${pageContext.request.contextPath}/assets/shipui/js/bootstrap.min.js?v=3.3.6"></script>


<!-- 自定义js -->
<script src="${pageContext.request.contextPath}/assets/shipui/js/content.js?v=1.0.0"></script>
<script src="${pageContext.request.contextPath}/assets/shipui/js/plugins/sweetalert/sweetalert.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/layui/layui.js" charset="utf-8"></script>

<script type="text/javascript">
    //postAjax
    function postAjax(url, data, fn) {
        $.ajax({
            url: url,
            data: data,
            type: 'post',
            contentType: "application/json",
            dataType: 'json',
            success: function (result) {
                fn(result);
            }
        });
    }

    function postAjax(url, data, fn, param) {
        $.ajax({
            url: url,
            data: data,
            type: 'post',
            contentType: "application/json",
            dataType: 'json',
            success: function (result) {
                fn(result, param);
            }
        });
    }

    function postAjax(url, data, fn, param, param1,param2) {
        $.ajax({
            url: url,
            data: data,
            type: 'post',
            contentType: "application/json",
            dataType: 'json',
            success: function (result) {
                fn(result, param, param1,param2);
            }
        });
    }

    function postAjax(url, data, fn, param, param1,param2,param3) {
        $.ajax({
            url: url,
            data: data,
            type: 'post',
            contentType: "application/json",
            dataType: 'json',
            success: function (result) {
                fn(result, param, param1,param2,param3);
            }
        });
    }
</script>

<script type="text/javascript">
    //查询计划列表
    function queryTransportPlan(data, fn, transportState) {
        $.ajax({
            url: "transportPlan/queryTransportPlan.do",
            data: data,
            type: 'post',
            contentType: "application/json",
            dataType: 'json',
            success: function (result) {
                fn(result, transportState);
            }
        });
    }
</script>

<script type="text/javascript">
    //显示下拉框数据
    function huoZhongSelect(result, huoZhongSelect, value) {
        if (result.SUCCESS) {
            var data = result.data;
            for (var i in data) {
                huoZhongSelect.append("<option value=" + data[i].goodsId + ">" + data[i].goodsName + "</option>")
            }
        }
        else {
            alert(result.MSG);
        }
        if ('' != value) {
            huoZhongSelect.val(value);
        }
    }

    function setPortSelect(result, portSelect, portSelect1,value,value1) {
        if (result.SUCCESS) {
            var data = result.data;
            for (var i in data) {
                portSelect.append("<option value=" + data[i].logisticsId + ">" + data[i].logisticsName + "</option>")
                portSelect1.append("<option value=" + data[i].logisticsId + ">" + data[i].logisticsName + "</option>")
            }
        }
        else {
            alert(result.MSG);
        }
        if ('' != value) {
            portSelect.val(value);
        }
        if ('' != value1) {
            portSelect1.val(value1);
        }
    }

    function setHuoZhuSelect(result, huoZhuSelect,value) {
        if (result.SUCCESS) {
            var data = result.data;
            for (var i in data) {
                huoZhuSelect.append("<option value=" + data[i].huoZhuId + ">" + data[i].huoZhuName + "</option>")
            }
        }
        else {
            alert(result.MSG);
        }
        if ('' != value) {
            huoZhuSelect.val(value);
        }
    }

    function showAddPlanData() {
        var data = JSON.stringify({});
        postAjax('config/queryGoodsConfig.do', data, huoZhongSelect, $("#huoZhong"),'');

        postAjax('config/queryLogisticsConfig.do', data, setPortSelect, $("#originalPort") , $("#destinationPort"),'','');

        postAjax('config/queryHuoZhuConfig.do', data, setHuoZhuSelect, $("#huoZhu"),'');

    }

    //显示修改框数据
    function showEditPlanData(result) {
        var resultJson = globalData[result];
        var data = JSON.stringify({});
        $("#planIdEdit").val(resultJson.planId);
        $("#transportStateEdit").val(resultJson.transportState);
        $("#transportStateNameEdit").val(resultJson.transportStateName);
        $("#tmsNumberEdit").val(resultJson.planName);
        postAjax('config/queryGoodsConfig.do', data, huoZhongSelect, $("#editHuoZhong"),resultJson.goodsId);
        postAjax('config/queryLogisticsConfig.do', data, setPortSelect, $("#editOriginalPort") , $("#editDestinationPort"),resultJson.originalId,resultJson.destinationId);
        postAjax('config/queryHuoZhuConfig.do', data, setHuoZhuSelect, $("#editHuoZhu"),resultJson.huoZhuId);
        $("#planTonEdit").val(resultJson.planTonnage);
        $("#planEmployEdit").val(resultJson.planHead);
        //编辑计划创建时间
        laydate.render({
            elem: '#startTimeEdit'
            ,type: 'datetime'
            ,value:resultJson.planStartDate
        });

        //编辑计划完成时间
        laydate.render({
            elem: '#endTimeEdit'
            ,type: 'datetime'
            ,value:resultJson.planEndDate
        });
    }
</script>

<script type="text/javascript">

    //    tab切换
    $(function () {
        $(".shipTabText").click(function () {
            $(".shipTabText").removeClass("shipTabText-click");
            $(this).addClass("shipTabText-click");
            if (5 == $(this).attr("state")) {
                var data = JSON.stringify({});
                queryTransportPlan(data, queryTransportPlanFn, 5);
            }
            else if (0 == $(this).attr("state")) {
                var data = JSON.stringify({transportState: 0});
                queryTransportPlan(data, queryTransportPlanFn, 0);
            }
            else if (1 == $(this).attr("state")) {
                var data = JSON.stringify({transportState: 1});
                queryTransportPlan(data, queryTransportPlanFn, 1);
            }
            else if (2 == $(this).attr("state")) {
                var data = JSON.stringify({transportState: 2});
                queryTransportPlan(data, queryTransportPlanFn, 2);
            }
            else if (3 == $(this).attr("state")) {
                var data = JSON.stringify({transportState: 3});
                queryTransportPlan(data, queryTransportPlanFn, 3);
            }
            else if (4 == $(this).attr("state")) {
                var data = JSON.stringify({transportState: 4})
                queryTransportPlan(data, queryTransportPlanFn, 4);
            }
        })
    });

    //初始化所有数据
    queryTransportPlan({}, queryTransportPlanFn, 5);

    var globalData;
    function queryTransportPlanFn(result, transportState) {
        var data = result.data;
        globalData = data;
        var content = "";
        for (var i = 0; i < data.length; i++) {
            var item = data[i];

            content += "<div class=\"col-xs-6 col-sm-4\">\n" +
                "                    <div class=\"ibox\" style='line-height: 1'>\n" +
                "                        <div class=\"ibox-title\" style=\"background-color: white\">\n" +
                "                            <span class=\"label pull-right\" style=\"background-color: white;margin-top: -5px\"><span style='font-size: 14px'>" + item.originalName + "</span> — <span style='font-size: 14px'>" + item.destinationName + "</span></span>\n" +
                "                            <h5>" + item.huoZhuName + "</h5>" +
                "<span class='planTxtStatus' id='planTxtStatusColor' style='background-color:"+item.transportStateColor+" '> "+ item.transportStateName + "</span>\n" +
                "                        </div>\n" +
                "                        <div class=\"ibox-content\">\n" +
                "                            <p><i class=\"fa fa-circle text-navy\" style=\"font-size: 5px\"></i><span\n" +
                "                                    style=\"margin-left: 10px\">计划负责人：" + item.planHead + "</span></p>\n" +
                "                            <p style='margin-top:6px'><i class=\"fa fa-circle text-primary\" style=\"font-size: 5px\"></i><span\n" +
                "                                    style=\"margin-left: 10px\">计划编号：" + item.planName + "</span></p>\n" +
                "                            <p style='margin-top:6px'><i class=\"fa fa-circle text-info\" style=\"font-size: 5px\"></i><span\n" +
                "                                    style=\"margin-left: 10px\">计划时间：" + item.planStartDate + "至" + item.planEndDate + "</span></p>\n" +
                "                            <p style='margin-top:6px'><i class=\"fa fa-circle text-warning\" style=\"font-size: 5px\"></i><span\n" +
                "                                    style=\"margin-left: 10px\">货物类型：" + item.goodsName + "</span></p>\n" +
                "                        </div>\n" +
                "                        <div class=\"ibox-title\">\n" +
                "                            <div class=\"row\" style=\"margin-top: -3px;font-weight: 300\">\n" +
                "                                <span class=\"col-sm-3  text-center planTxt\" onclick=exportExcel(1,'" + item.planId + "',null)>导出</span>\n" +
                "                                <span class=\"col-sm-1  text-center\" style='color:slategray'>|</span>\n" +
                "                                <button id='editPlanButton' style='border: 0;background-color: transparent;outline: none;' class=\"col-sm-3 text-center\ planTxt\" data-toggle=\"modal\" data-target=\"#editPlan\" onclick=showEditPlanData('" + i + "')>编辑</button>\n" +
                "                                <span class=\"col-sm-1  text-center\" style='color:slategray'>|</span>\n" +
                "                                <span class=\"col-sm-3 text-center\ planTxt\" onclick=goTransportDetail('" + item.planId + "')> 查看</span>\n" +
                "                            </div>\n" +
                "                        </div>\n" +
                "                    </div>\n" +
                "                </div>";

            // document.getElementById('planTxtStatusColor').style.background=item.transportStateColor;

        }
        if (5 == transportState) {
            $("#allShip").html(content);
        }
        else if (0 == transportState) {
            $("#planWks").html(content);
        }
        else if (1 == transportState) {
            $("#planYsz").html(content);
        }
        else if (2 == transportState) {
            $("#planWc").html(content);
        }
        else if (3 == transportState) {
            $("#planYq").html(content);
        }
        else if (4 == transportState) {
            $("#planZz").html(content);
        }

        if (content==""){
            swal({
                title: "未找到相关计划！",
                type: "warning"
            });
        }

        $("#orderNumberSearch").val("");
        $("#huoZhuSearch").val("");
        $("#timeSearch").val("");

    }

    //     搜索运输计划
    function searchPlan() {
        var orderNumberSearch = $("#orderNumberSearch").val();
        var huoZhuSearch = $("#huoZhuSearch").val();
        var timeSearch = $("#timeSearch").val();
        var data = JSON.stringify({planName: orderNumberSearch, huoZhuName: huoZhuSearch, createTime: timeSearch});
             queryTransportPlan(data, queryTransportPlanFn, 5);
             $(".shipTabText").removeClass("shipTabText-click");
             $(".tab-pane").removeClass("in active");
             $(allShipSpan).addClass("shipTabText-click");
             $(allShip).addClass("in active");
    }

    var laydate;
    layui.use('laydate', function () {
        laydate = layui.laydate;
        laydate.render({
            elem: '#timeSearch'
            , type: 'date'
            , range: true //或 range: '~' 来自定义分割字符
        });

        //计划创建时间
        laydate.render({
            elem: '#startTime'
            ,type: 'datetime'
        });

        //计划完成时间
        laydate.render({
            elem: '#endTime'
            ,type: 'datetime'
        });

    });

    //     新增运输计划
    function addPlanModel() {
        var planName = $("#tmsNumber").val();
        var goodsId = $("#huoZhong").val();
        var huoZhuId = $("#huoZhu").val();
        var original = $("#originalPort").val();
        var destination = $("#destinationPort").val();
        var planTonnage = $("#planTon").val();
        var planHead = $("#planEmploy").val();
        var planStartDate = $("#startTime").val();
        var planEndDate = $("#endTime").val();

        if (!planName || !goodsId || !huoZhuId || !original || !destination || !planTonnage || !planHead || !planStartDate || !planEndDate) {
            swal({
                title: "请输入计划信息",
                type: "warning"
            });
            return;
        }

        var data = JSON.stringify({
            "planName": planName,
            "goodsId": goodsId,
            "huoZhuId": huoZhuId,
            "original": original,
            "destination": destination,
            "planTonnage": planTonnage,
            "planHead": planHead,
            "planStartDate": planStartDate,
            "planEndDate": planEndDate
        });
        postAjax('transportPlan/addTransportPlan.do', data, fnAlertAddPlanModel);
    }

    function fnAlertAddPlanModel(result) {
        if (result.SUCCESS) {
            swal({
                title: "新增计划成功",
                type: "success"
            },function () {
                location.reload();
            });
        }
        else {
            swal({
                title: result.MSG,
                type: "warning"
            });
        }
    }

    // 修改运输计划
    function editPlanModel() {
        var planId = $("#planIdEdit").val();
        var planName = $("#tmsNumberEdit").val();
        var goodsId = $("#editHuoZhong").val();
        var huoZhuId = $("#editHuoZhu").val();
        var original = $("#editOriginalPort").val();
        var destination = $("#editDestinationPort").val();
        var planTonnage = $("#planTonEdit").val();
        var planHead = $("#planEmployEdit").val();
        var planStartDate = $("#startTimeEdit").val();
        var planEndDate = $("#endTimeEdit").val();

        if (!planId || !planName || !goodsId || !huoZhuId || !original || !destination || !planTonnage || !planHead || !planStartDate || !planEndDate) {
            alert("请输入计划信息");
            return;
        }

        if ("2,3,4".indexOf($("#transportStateEdit").val()) > -1) {
            swal({
                title: "该计划处于" + $("#transportStateNameEdit").val() + "状态，不能编辑",
                type: "warning"
            });
            return false;
        }

        var data = JSON.stringify({
            "planId":planId,
            "planName": planName,
            "goodsId": goodsId,
            "huoZhuId": huoZhuId,
            "original": original,
            "destination": destination,
            "planTonnage": planTonnage,
            "planHead": planHead,
            "planStartDate": planStartDate,
            "planEndDate": planEndDate
        });
        postAjax('transportPlan/editTransportPlan.do', data, fnAlertEditPlanModel);
    }

    function fnAlertEditPlanModel(result) {
        if (result.SUCCESS) {
            swal({
                title: "编辑计划成功",
                type: "success"
            },function () {
                location.reload();
            });
        }
        else {
            swal({
                title: result.MSG,
                type: "warning"
            });
        }
    }

    function exportExcel(from, planId, transportState) {
        var param='';
        if (1 == from) {
            param = "?planId="+planId;
        }
        else if (2 == from) {
            param = "?transportState="+transportState;
        }
        $("#downloadExcel").attr("href","transportPlan/exportTransportExcel.do" + param);
        var a = document.getElementById("downloadExcel");
        a.click();
    }

    function goTransportDetail(planID) {
        // alert(planID);
        window.location.href="toTransportDetail.do?planId="+planID;
    }

    $(function () {
        var orderNumberSearch = $("shipName").val();
        if (orderNumberSearch !=""){
            $("body").keydown(function() {
                if (event.keyCode == "13") {//keyCode=13是回车键
                    $('#orderNumberSearchButton').click();
                }
            });
        }

    });

</script>

</body>

</html>
